home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 5 / QRZ Ham Radio Callsign Database - Volume 5.iso / files / tcpip / amiga / asrc29p.lha / slcompre.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  7.2 KB  |  210 lines

  1. /*
  2.  * Definitions for tcp compression routines.
  3.  *
  4.  * $Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $
  5.  *
  6.  * Copyright (c) 1989 Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms are permitted
  10.  * provided that the above copyright notice and this paragraph are
  11.  * duplicated in all such forms and that any documentation,
  12.  * advertising materials, and other materials related to such
  13.  * distribution and use acknowledge that the software was developed
  14.  * by the University of California, Berkeley.  The name of the
  15.  * University may not be used to endorse or promote products derived
  16.  * from this software without specific prior written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  *    Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
  22.  *    - Initial distribution.
  23.  */
  24. /*
  25.  * modified for KA9Q Internet Software Package by
  26.  * Katie Stevens (dkstevens@ucdavis.edu)
  27.  * University of California, Davis
  28.  * Computing Services
  29.  *    - 01-31-90    initial adaptation
  30.  */
  31. #include "global.h"
  32.  
  33. #ifndef SL_TYPE_IP
  34.  
  35. #define MLEN 128
  36. #define MAX_STATES 16        /* must be > 2 and < 256 */
  37. #define MAX_HDR MLEN        /* XXX 4bsd-ism: should really be 128 */
  38.  
  39. /*
  40.  * Compressed packet format:
  41.  *
  42.  * The first octet contains the packet type (top 3 bits), TCP
  43.  * 'push' bit, and flags that indicate which of the 4 TCP sequence
  44.  * numbers have changed (bottom 5 bits).  The next octet is a
  45.  * conversation number that associates a saved IP/TCP header with
  46.  * the compressed packet.  The next two octets are the TCP checksum
  47.  * from the original datagram.  The next 0 to 15 octets are
  48.  * sequence number changes, one change per bit set in the header
  49.  * (there may be no changes and there are two special cases where
  50.  * the receiver implicitly knows what changed -- see below).
  51.  * 
  52.  * There are 5 numbers which can change (they are always inserted
  53.  * in the following order): TCP urgent pointer, window,
  54.  * acknowlegement, sequence number and IP ID.  (The urgent pointer
  55.  * is different from the others in that its value is sent, not the
  56.  * change in value.)  Since typical use of SLIP links is biased
  57.  * toward small packets (see comments on MTU/MSS below), changes
  58.  * use a variable length coding with one octet for numbers in the
  59.  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
  60.  * range 256 - 65535 or 0.  (If the change in sequence number or
  61.  * ack is more than 65535, an uncompressed packet is sent.)
  62.  */
  63.  
  64. /*
  65.  * Packet types (must not conflict with IP protocol version)
  66.  *
  67.  * The top nibble of the first octet is the packet type.  There are
  68.  * three possible types: IP (not proto TCP or tcp with one of the
  69.  * control flags set); uncompressed TCP (a normal IP/TCP packet but
  70.  * with the 8-bit protocol field replaced by an 8-bit connection id --
  71.  * this type of packet syncs the sender & receiver); and compressed
  72.  * TCP (described above).
  73.  *
  74.  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
  75.  * is logically part of the 4-bit "changes" field that follows.  Top
  76.  * three bits are actual packet type.  For backward compatibility
  77.  * and in the interest of conserving bits, numbers are chosen so the
  78.  * IP protocol version number (4) which normally appears in this nibble
  79.  * means "IP packet".
  80.  */
  81.  
  82. /* SLIP compression masks for len/vers byte */
  83. #define SL_TYPE_IP 0x40
  84. #define SL_TYPE_UNCOMPRESSED_TCP 0x70
  85. #define SL_TYPE_COMPRESSED_TCP 0x80
  86. #define SL_TYPE_ERROR 0x00
  87.  
  88. /* Bits in first octet of compressed packet */
  89. #define NEW_C    0x40    /* flag bits for what changed in a packet */
  90. #define NEW_I    0x20
  91. #define NEW_S    0x08
  92. #define NEW_A    0x04
  93. #define NEW_W    0x02
  94. #define NEW_U    0x01
  95.  
  96. /* reserved, special-case values of above */
  97. #define SPECIAL_I (NEW_S|NEW_W|NEW_U)        /* echoed interactive traffic */
  98. #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)    /* unidirectional data */
  99. #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
  100.  
  101. #define TCP_PUSH_BIT 0x10
  102.  
  103. /*
  104.  * data type and sizes conversion assumptions:
  105.  *
  106.  *    VJ code        KA9Q style    generic    
  107.  *    u_char        unsigned char    unsigned char     8 bits
  108.  *    u_short        int16        unsigned short    16 bits
  109.  *    u_int        int16        unsigned short    16 bits
  110.  *    u_long        unsigned long    unsigned long    32 bits
  111.  *    int        int32        long        32 bits
  112.  */
  113.  
  114. /*
  115.  * define header structures to allow scan of IP and TCP
  116.  * headers of packets ready for transmission
  117.  */
  118. struct iphdr {
  119.     unsigned char ipvers_hlen;
  120.     unsigned char ip_tos;
  121.     int16 ip_totlen;
  122.     int16 ip_id;
  123.     int16 ip_fragoff;
  124.     unsigned char ip_ttl;
  125.     unsigned char ip_protocol;
  126.     int16 ip_csum;
  127.     unsigned long ip_source;
  128.     unsigned long ip_dest;
  129. };
  130. struct tcphdr {
  131.     int16 th_sport;
  132.     int16 th_dport;
  133.     unsigned long th_seq;
  134.     unsigned long th_ack;
  135.     unsigned char th_off;
  136.     unsigned char th_flags;
  137. #define    TH_FIN    0x01
  138. #define    TH_SYN    0x02
  139. #define    TH_RST    0x04
  140. #define    TH_PUSH    0x08
  141. #define    TH_ACK    0x10
  142. #define    TH_URG    0x20
  143.     int16 th_win;
  144.     int16 th_csum;
  145.     int16 th_urgpt;
  146. };
  147.  
  148.  
  149. /*
  150.  * "state" data for each active tcp conversation on the wire.  This is
  151.  * basically a copy of the entire IP/TCP header from the last packet
  152.  * we saw from the conversation together with a small identifier
  153.  * the transmit & receive ends of the line use to locate saved header.
  154.  */
  155. struct cstate {
  156.     struct cstate *cs_next;    /* next most recently used cstate (xmit only) */
  157.     int16 cs_hlen;        /* size of hdr (receive only) */
  158.     unsigned char cs_id;    /* connection # associated with this state */
  159.     unsigned char cs_filler;
  160.     union {
  161.         char csu_hdr[MAX_HDR];
  162.         struct iphdr csu_ip;    /* ip/tcp hdr from most recent packet */
  163.     } slcs_u;
  164. };
  165. #define cs_ip slcs_u.csu_ip
  166. #define cs_hdr slcs_u.csu_hdr
  167.  
  168. /*
  169.  * all the state data for one serial line (we need one of these
  170.  * per line).
  171.  */
  172. struct slcompress {
  173.     struct cstate *last_cs;    /* most recently used tstate */
  174.     unsigned char last_recv;    /* last rcvd conn. id */
  175.     unsigned char last_xmit;    /* last sent conn. id */
  176.     int16 flags;
  177. #ifndef SL_NO_STATS
  178.     int32 sls_nontcp;    /* outbound non-TCP packets */
  179.     int32 sls_asistcp;    /* outbound TCP packets */
  180.     int32 sls_compressed;    /* outbound compressed packets */
  181.     int32 sls_uncompressed;    /* outbound uncompressed packets */
  182.     int32 sls_searches;    /* searches for connection state */
  183.     int32 sls_misses;    /* times couldn't find conn. state */
  184.     int32 sls_nontcpin;    /* inbound non-TCP packets */
  185.     int32 sls_tcpin;    /* inbound TCP packets */
  186.     int32 sls_uncompressedin;    /* inbound uncompressed packets */
  187.     int32 sls_compressedin;    /* inbound compressed packets */
  188.     int32 sls_errorin;    /* inbound unknown type packets */
  189.     int32 sls_tossed;    /* inbound packets tossed because of error */
  190. #endif
  191.     struct cstate tstate[MAX_STATES];    /* xmit connection states */
  192.     struct cstate rstate[MAX_STATES];    /* receive connection states */
  193. };
  194. /* flag values */
  195. #define SLF_TOSS 1        /* tossing rcvd frames because of input err */
  196. /* Null pointer */
  197. #define NULLSLCOMPR    (struct slcompress *)0
  198.  
  199. extern struct slcompress *Slcomp;
  200.  
  201. /* In slcompress.c: */
  202. void sl_compress_init __ARGS((struct slcompress *comp));
  203. unsigned char sl_compress_tcp __ARGS((struct mbuf **bpp,
  204.     register struct iphdr *iph, struct slcompress *comp,
  205.     int compress_cid));
  206. int sl_uncompress_tcp __ARGS((struct mbuf **bufp, int len,
  207.     int16 type, struct slcompress *comp));
  208.  
  209. #endif
  210.